package com.ruoyi.equipment.controller;

import com.hz.rouyigonggong.domain.basedomain.BaseDomain;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.equipment.domain.LgEquipmentError;
import com.ruoyi.equipment.service.impl.LgEquipmentErrorServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author: lek
 * @Description: TODO
 * @Date: 2025/3/10 14:51
 * @Version: 1.0
 */
@RestController
@RequestMapping("/error")
public class LgEquipmentErrorController extends BaseController {
    @Autowired
    private LgEquipmentErrorServiceImpl lgEquipmentErrorService;
    /**
     * 获取参数配置列表
     */
    @GetMapping("/list")
    public TableDataInfo list(LgEquipmentError lgEquipmentError)
    {
        startPage();
        lgEquipmentError.setCreateBy(String.valueOf(BaseDomain.getUserId()));
        List<LgEquipmentError> list = lgEquipmentErrorService.selectLgEquipmentErrorList(lgEquipmentError);
        return getDataTable(list);

    }

    @Log(title = "参数管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LgEquipmentError lgEquipmentError)
    {
        List<LgEquipmentError> list = lgEquipmentErrorService.selectLgEquipmentErrorList(lgEquipmentError);
        ExcelUtil<LgEquipmentError> util = new ExcelUtil<LgEquipmentError>(LgEquipmentError.class);
        util.exportExcel(response, list, "参数数据");
    }

    /**
     * 根据参数编号获取详细信息
     */
    @GetMapping(value = "/{errorId}")
    public AjaxResult getInfo(@PathVariable Integer errorId)
    {
        return success(lgEquipmentErrorService.selectLgEquipmentErrorById(errorId));
    }

    /**
     * 新增参数配置
     */
    @Log(title = "参数管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody LgEquipmentError lgEquipmentError)
    {
        lgEquipmentError.setCreateBy(String.valueOf(BaseDomain.getUserId()));
        return toAjax(lgEquipmentErrorService.insertLgEquipmentError(lgEquipmentError));
    }

    /**
     * 修改参数配置
     */
    @Log(title = "参数管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody  LgEquipmentError lgEquipmentError)
    {
        return toAjax(lgEquipmentErrorService.updateLgEquipmentError(lgEquipmentError));
    }

    /**
     * 删除参数配置
     */
    @Log(title = "参数管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{errorIds}")
    public AjaxResult remove(@PathVariable Integer[] errorIds)
    {
        lgEquipmentErrorService.deleteLgEquipmentErrorByIds(errorIds);
        return success();
    }
}
